class EventsController < ApplicationController
	layout 'standard' 
	def new
		@event = Event.new
		@event_times = EventTime.find(:all, :conditions => "event_id = 0")
	end
	
	def create
		@event = Event.new(params[:event])
		@event_times = EventTime.find(:all, :conditions => "event_id = 0")
		if @event.save
			@event_times.each do |e|
				e.update_attributes("event_id" => @event.id)
			end
			@users = User.find(:all, :conditions => ["event_id = ?", @event.id])
			@best = EventTime.find(:all, :limit => 3, :order=>'(date_end - date_begin) DESC')
		else
			redirect_to :controller => 'user', :action => 'error'
		end
	end
	
	def show
		#this will eventually show event page
	
		@event = Event.find(params[:id])
		@users = User.find(:all, :conditions => ["event_id = ?", @event.id])
		@event_times = EventTime.find(:all, :conditions => ["event_id = ?", @event.id])
		@best = EventTime.find(:all, :limit => 3, :order => "count", :conditions => ["event_id = ?", @event.id])
	end
end
